@tool
class_name Skill_Action_CreateGhost
extends SkillAction

#region 属性
@export var duration_range:Vector2 = Vector2.ONE
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
## 初始化
func init(action_idx:int = -1,init_data:Dictionary = {},handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
	super.init(action_idx,init_data,self_handle_func)
## 释放
func release(args:Dictionary = {},handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
		var duration = GameManager.get_grng().grng_randf_range(duration_range.x,duration_range.y)
		var agent = get_agent()
		var animation_component:AnimationComponent = agent.entity.get_component(AnimationComponent)
		if animation_component and animation_component.sprite_2d:
			var clone = animation_component.sprite_2d.duplicate()
			clone.set_script(Ghost)
			clone.init_ghost(duration)
			## TODO 先暂时丢到MapSystem下面吧
			GameMapSystem.add_child(clone)
			clone.global_position = animation_component.sprite_2d.global_position
	super.release(args,self_handle_func)
## 打断
func interrupt(handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
	super.interrupt(self_handle_func)
## 完成
func complete(release_result:GameEnum.SkillReleaseResult = GameEnum.SkillReleaseResult.Success,handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
	super.complete(release_result,self_handle_func)
## 冷却
func cool(handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
	super.cool(self_handle_func)
## 冷却完成
func cool_complete(handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
	super.cool_complete(self_handle_func)
## 重置冷却
func reset_cool(handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
	super.reset_cool(self_handle_func)
## 销毁
func destroy(handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
	super.destroy(self_handle_func)
## 判断该技能能否释放
func check_can_release() -> GameEnum.SkillReleaseStatus:
	var res = super.check_can_release()
	if res != GameEnum.SkillReleaseStatus.Success:
		return res
	var agent = get_agent()
	if not agent:
		return GameEnum.SkillReleaseStatus.Failure
	return GameEnum.SkillReleaseStatus.Success
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
#endregion
